﻿using System;
using System.Linq;
using System.Web;

namespace Olemas.ViewModels
{
    public abstract class GlobalViewModel
    {
        public int FacultyId { get; protected set; }
        public int NumberOfPages { get; protected set; }
        public int CurrentPage { get; protected set; }
        public string PagesRemaining { get; protected set; }

        /// <summary>
        /// Get total number of pages
        /// </summary>
        /// <param name="items">The total number of items.</param>
        /// <param name="pageSize">The number of items that fit on one page.</param>
        public static int GetTotalPages(int items, int pageSize)
        {
            var totalPages = Convert.ToInt32(Math.Ceiling((double)items / pageSize));
            return totalPages;
        }

        /// <summary>
        /// Gets the string representation of the remaining pages ("Veel XX lehte").
        /// </summary>
        /// <param name="total">The total number of pages.</param>
        /// <param name="current">The current page number.</param>
        public static string RemainingPages(int total, int current)
        {
            var remaining = total - current;
            switch (remaining)
            {
                case 1:
                    return "↓ Veel 1 leht ↓";
                case 0:
                    return "↑ Kõik vaadatud. Tagasi üles ↑";
                default:
                    return String.Format("↓ Veel {0} lehte ↓", remaining);
            }
        }

        public static bool IsImage(HttpPostedFileBase file)
        {
            if (file.ContentType.Contains("image"))
            {
                return true;
            }

            var formats = new string[] { ".jpg", ".png", ".gif", ".jpeg" }; // add more if u like...

            return formats.Any(item => file.FileName.EndsWith(item, StringComparison.OrdinalIgnoreCase));
        }
    }


}